package com.easylinkin.linkappapi.lobar.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.lobar.entity.LobarSet;
import com.easylinkin.linkappapi.lobar.service.LobarSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: 劳务设置管理
 */
@RestController
@RequestMapping("lobarSet")
@Api(tags = "劳务设置管理")
public class LobarSetController {
  
  @Autowired
  private LobarSetService lobarSetService;

  /**
   * @Description: 增加劳务设置
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping
  @ApiOperation("增加劳务设置")
  public RestMessage insert(@RequestBody LobarSet lobarSet){
    //todo 参数验证
    lobarSetService.insert(lobarSet);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 删除劳务设置（包含批量删除）
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @DeleteMapping
  @ApiOperation("删除劳务设置（包含批量删除）")
  public RestMessage delBatch(@RequestBody LobarSet lobarSet){
    Assert.notEmpty(lobarSet.getIds(),"id不能为空");
    lobarSetService.removeByIds(lobarSet.getIds());
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 编辑劳务设置
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PutMapping
  @ApiOperation("编辑劳务设置")
  public RestMessage updateById(@RequestBody LobarSet lobarSet){
    Assert.notNull(lobarSet.getId(),"id不能为空");
    lobarSetService.updateOne(lobarSet);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 获取当前项目配置
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @GetMapping
  @ApiOperation("获取当前项目配置")
  public RestMessage findOne() {
    LobarSet lobarSet = lobarSetService.findOne();
    return RestBuilders.successBuilder().data(lobarSet).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<LobarSet> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<LobarSet> record =  lobarSetService.queryListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }
}

